#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

#define PORT 6969
#define DEFAULT_ADDRESS "224.0.0.213"
#define DEFAULT_SECONDS_INTERVAL 1


int main(void)
{
    int sockfd;

    if((sockfd = socket(AF_INET, SOCK_DGRAM,0)) == -1)
    {
        perror("socket");
        exit(1);
    }


    struct sockaddr_in multicast_addr;

    multicast_addr.sin_family = AF_INET;
    multicast_addr.sin_port = htons(PORT);
    multicast_addr.sin_addr.s_addr = inet_addr(DEFAULT_ADDRESS);
    memset(&(multicast_addr.sin_zero), '\0', 8);

    char* buf = "o.O\0";

    int numbytes;

    struct timeval tv;


    for(;;)
    {
        tv.tv_sec = DEFAULT_SECONDS_INTERVAL;
        tv.tv_usec = 0;
        select(NULL,NULL,NULL,NULL,&tv);

        if((numbytes = sendto(sockfd,buf,strlen(buf)+1,0,(struct sockaddr *)&multicast_addr,sizeof(struct sockaddr))) == -1)
        {
            perror("sendto");;
            exit(1);
        }
    }
    close(sockfd);

    return 0;
}
